package com.imti.utils;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaModel;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        shortMessage("18192835995","985248");
    }



    /**
     * 短信接口
     */
    public static void shortMessage(String phone ,String code)throws Exception{
        /*String[] args_=null;
        java.util.List<String> args = java.util.Arrays.asList(args_);*/
        com.aliyun.dysmsapi20170525.Client client = Sample.createClient("LTAI5t8trEs5FZLjetc6dtDT", "xUD08twgXgHSacIQTbrc3F7aDjhMS6");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("周俊琪个人网站")
                .setTemplateCode("SMS_268581115")
                .setPhoneNumbers(phone)
                .setTemplateParam("{\"code\":"+code+"}");
        RuntimeOptions runtime = new RuntimeOptions();
        SendSmsResponse resp = client.sendSmsWithOptions(sendSmsRequest, runtime);
        com.aliyun.teaconsole.Client.log(Common.toJSONString(TeaModel.buildMap(resp)));
    }
}

